import Utils from "../../../core/utils";
import { Dashboard } from "../../test_dashboard/dashboard";

const { ccclass, property } = cc._decorator;

@ccclass
export default class PageGameTest extends cc.Component {
    @property(cc.Label)
    text: cc.Label = null;
    db: Dashboard = null;


    protected onDisable(): void {
        if (this.db) {
            this.db.dispose();
            this.db = null;
        }
    }
    initDashboard() {
        let db = new Dashboard(this.node.name);

        db.attrBtn("按钮", "测试", function () {
            Utils.game.msgBox("你点击了测试按钮");
        }.bind(this));

        db.col();
        db.text("控制TEST属性");
        db.attrNumRange("x", 0, 375, -375, 1, function (val) {
            this.text.node.x = val;
        }.bind(this));
        db.attrNumRange("y", 0, 600, -600, 1, function (val) {
            this.text.node.y = val;
        }.bind(this));
        db.end();

        this.db = db;
    }
    onToggleDashboard() {
        if (!this.db) {
            this.initDashboard();
        }
        this.db.toggle();
    }
}
